package com.example.springbootmybatisplus;

import com.example.springbootmybatisplus.pojo.User;
import com.example.springbootmybatisplus.service.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;

/**
 * @auther 尚智江
 * @Date 2022/10/13 0:08
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class Service {
    @Autowired
    private UserService userService;
    @Test
    public void testGetCount(){
        // SELECT COUNT( * ) FROM user
        // 查询总记录数
        long l = userService.count();
        System.out.println("总记录数"+l);
    }
    @Test
    public void insertMore(){
        // 批量插入数据
        // INSERT INTO user ( id, name, age ) VALUES ( ?, ?, ? )
        ArrayList<User> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            User user = new User();
            user.setName("hh"+ i);
            user.setAge(20 + i);
            list.add(user);
        }
        boolean b = userService.saveBatch(list);
        System.out.println(b);
    }
}
